package com.just.bz_back.scheduling;


import com.just.bz_back.model.dto.MonitorInfoBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;




//@Configuration
public class CPUScheduling {

    @Scheduled(cron = " * 0/2 * * * *")
    private void showCpu()
    {
        int m = 1024;
        int kb = 1024;

        // 可使用内存
        long totalMemory = Runtime.getRuntime().totalMemory() / kb / m;
        // 剩余内存
        long freeMemory = Runtime.getRuntime().freeMemory() / kb / m;
        // 最大可使用内存
        long maxMemory = Runtime.getRuntime().maxMemory() / kb /m;

        //内存使用率
        long memoryRatio = freeMemory * 100 / maxMemory;
        // 构造返回对象
        MonitorInfoBean infoBean=new MonitorInfoBean(totalMemory,freeMemory,maxMemory,memoryRatio);
        System.out.println(infoBean.toString());
    }



}
